package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Configuration
@Slf4j
@RestControllerAdvice
public class ExceptionCatch {
    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception e) {
        log.error("ExceptionCatch e:{}",e);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"您的网络异常，请稍后重试！");
    }
    @ExceptionHandler(CustomException.class)
    public ResponseResult custException(CustomException e){
        log.error("CustomException e->{}",e);
        return ResponseResult.errorResult(e.getAppHttpCodeEnum());
    }
}
